package cn.itsource.cw.controller;

import cn.itsource.cw.entity.TbDept;
import cn.itsource.cw.service.dept.DeptServiceImpl;
import cn.itsource.cw.vo.PageResult;
import cn.itsource.cw.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/dept")
public class DeptController {
    @Autowired
    private DeptServiceImpl deptService;

    @PostMapping("/insert")
    public Result insertDept(@RequestBody TbDept dept) {
        deptService.insertDept(dept);
        return new Result(true);
    }

    @PostMapping("/update")
    public Result updateDept(@RequestBody TbDept dept) {
        deptService.updateDept(dept);
        return new Result(true);
    }

    @PostMapping("/findpage")
    public PageResult<TbDept> findPageByParam(@RequestBody TbDept param, int pageNum, int pageSize) {
        return deptService.findPageByParam(param, pageNum, pageSize);
    }

    @GetMapping("/findbyid/{id}")
    public TbDept findById(@PathVariable("id") Integer id) {
        TbDept dept =  deptService.findDeptById(id);
        dept.setContent("这是我从后台手动修改的测试数据");
        return dept;
    }
}
